package app.biz.controller;

import app.biz.model.EcgResponse;
import app.framework.controller.base.BaseController;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.RandomUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 沙箱：用于模拟远程服务请求
 * */
@RestController
public class SandboxController extends BaseController {
	private static final Logger logger = LoggerFactory.getLogger(SandboxController.class);
	JSONObject success;
	@PostMapping("/ins/json")
	  public JSONObject ecgBox() throws InterruptedException {
		if(success!=null){
			return success;
		}
		String resultStr = "{\"code\": \"?\", \"status\": 0, \"error\": \"?\", \"result\": {\"symptom_code\": \"[0,11,12]\", \"normal\": \"1\"}}";
		 success =  EcgResponse.instance.success(RandomUtils.nextLong(),JSONObject.parseObject(resultStr));
         logger.info("开始模拟等待。。。");
		 Thread.sleep(10000);//模拟超时异常
		return success;
	}

}
